/* 
 * File:   skpng.h
 * Version:0.1
 * Author: Jacques HULLU
 * Email: jacques@hullu.fr
 *
 * Created on 21 septembre 2010, 10:57
 */

#ifndef SKPNG_H
#define	SKPNG_H
#include <png.h>
#endif	/* SKPNG_H */

/**
 Needed information about libpng structure
 */
typedef struct skpng_image_info_str {
    unsigned int width, height ;
    Byte bit_depth, color_type ;
} skpng_image_info;

/**
 Image data + info
 */
typedef struct skpng_image_str {
    skpng_image_info pngimageinfo;
    png_bytepp pngimage ;
} skpng_image ;

/**
 RGBA info use for color manipulation
 */
typedef struct skpng_image_color_layer_str {
    float R,G,B,A ;
} skpng_image_color_layer ;
typedef skpng_image_color_layer skpng_icl;

/* 
 * ==== FORMULAS ======================
 * 
 */

/**
 * 
 * Compute RGBA channel to make alphablending "beautiful"
 * 
 * @param RGBA  Chanel value of background image
 * @param rgba  Chanel value of foreground image
 * @param alphafactor   Factor of transparency
 * @return
 */
skpng_icl skpng_formula_alphablending(skpng_icl*, skpng_icl*, float) ;

/*
 * ==== END OF FORMULAS ==============
 */

/* 
 * ==== PROCESSING ======================
 * 
 */

/**
 * 
 * Merge two images in one. The second will apply an alphablending operation
 * 
 * @param image1_ptr    Image data in skpng format
 * @param image2_ptr    Image data in skpng format
 * @param imageO_ptr    Image data in skpng format
 * @param alpha_percent Factor of transparency (not used)
 * @return
 */
int skpng_proceed_merge(skpng_image*, skpng_image*, skpng_image*, float) ;

/**
 * 
 * Extract the diff between image1 & image2 and put it in imageO
 * 
 * @todo alphapercent and bgcolor are not used in this version
 * @param image1_ptr    Image data in skpng format
 * @param image2_ptr    Image data in skpng format
 * @param imageO_ptr    Data of image0 in skpng format
 * @param alpha_percent Factor of transparency (not used)
 * @param bgcolor       Background color (not used)
 * @return
 */
int skpng_proceed_extractdiff(skpng_image*, skpng_image*, skpng_image*, float, int) ;
/*
 * ==== END OF PROCESSING ==============
 */

/**
 * 
 * Read a png file (RGBA only)
 * 
 * @param filename  Name of file to read
 * @param image1    Image Data
 * @return
 */
int skpng_read(char*, skpng_image*) ;

/**
 * 
 * Prepare the output file from a model "image1"
 * 
 * @param filename  Name of the output file
 * @param image1    Image data in skpng format
 * @return
 */
int skpng_prepare_output_file(char*, skpng_image*) ;

/**
 * 
 * Write the png file
 * 
 * @param filename  Name of file
 * @param image1    Image data
 * @return
 */
int skpng_write(char*, skpng_image*) ;


/**
 * 
 * Return current and compiled version of libpng
 * 
 */
void skpng_png_version_info(void) ;
